home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1989 / 05 / coop.c < prev    next >
C/C++ Source or Header  |  1989-07-03  |  3KB  |  129 lines

  1. /*
  2.     COOP.C - functions to handle twll structure and related structures
  3.  
  4.     add_twll()              - insert a new item on the top of the list
  5.     add_data_twll()         - add a new data_twll item by calling add_twll()
  6.     print_twll()            - print a description of the item's type
  7.     print_data_twll()       - print values and call print_twll()
  8.     print_my_data_twll()    - print values and call print_data_twll()
  9.     print_other_data_twll() - print values and call print_data_twll()
  10.  
  11. */
  12.  
  13. #include "coop.h"
  14.  
  15.  
  16. /* -----------------------------------------------------------------
  17.  Add a new item to the top of a two way linked list
  18. */
  19.  
  20. add_twll(head,twll,type)
  21. struct TWLL_HEAD *head;
  22. struct TWLL    *twll;
  23. int              type;
  24. {
  25.     struct TWLL *cur;
  26.  
  27.     cur        =head->top;
  28.     twll->prev =0;
  29.     twll->next =cur;
  30.     if (cur) {
  31.         cur->prev  =twll;
  32.         head->top  =twll;
  33.         head->cnt++;
  34.         }
  35.     head->top=twll;
  36.     twll->type=type;
  37. }
  38.  
  39.  
  40.  
  41. /* -----------------------------------------------------------------
  42.  This function inits any struct that starts with DATA_TWLL.
  43.  
  44.  These structures must have x and y inited to 5 and 6.
  45.  
  46.  It then calls the regular add function to insert the struct.
  47. */
  48.  
  49. add_data_twll(head,twll,type)
  50. struct HEAD_TWLL *head;
  51. struct DATA_TWLL *twll;
  52. int              type;
  53.  
  54. {
  55.     twll->x=5;
  56.     twll->y=6;
  57.     add_twll(head,twll,type);
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64. /* -----------------------------------------------------------------
  65.  Print the data type
  66.  
  67. */
  68.  
  69. print_twll(twll)
  70. struct TWLL *twll;
  71. {
  72.     switch (twll->type) {
  73.         case DATA:
  74.             printf("type is DATA\n");
  75.             break;
  76.         case MY_DATA:
  77.             printf("type is MY_DATA\n");
  78.             break;
  79.         case OTHER_DATA:
  80.             printf("type is OTHER_DATA\n");
  81.             break;
  82.         }
  83.     return;
  84. }
  85.  
  86.  
  87.  
  88.  
  89.  
  90. /* -----------------------------------------------------------------
  91.  Print the data in a DATA_TWLL
  92. */
  93.  
  94. print_data_twll(twll)
  95. struct DATA_TWLL *twll;
  96.  
  97. {
  98.     printf("x is %d, y is %d \t",twll->x,twll->y);
  99.     print_twll(twll);
  100. }
  101.  
  102.  
  103.  
  104. /* -----------------------------------------------------------------
  105.  Print the data in a MY_DATA_TWLL
  106. */
  107.  
  108. print_my_data_twll(twll)
  109. struct MY_DATA_TWLL *twll;
  110. {
  111.     printf("a is %s \t",twll->a);
  112.     print_data_twll(twll);
  113. }
  114.  
  115.  
  116.  
  117.  
  118. /* -----------------------------------------------------------------
  119.  Print the data in a OTHER_DATA_TWLL
  120. */
  121.  
  122. print_other_data_twll(twll)
  123. struct OTHER_DATA_TWLL *twll;
  124. {
  125.      printf("a is %d \t",twll->a);
  126.      print_data_twll(twll);
  127.  
  128. }
  129.